clear
clear matrix
program drop _all
capture log close
cd C:\Users\dpage\Desktop\Clash_Project\

use Latinobarometro_2015_Eng.dta, clear 

set more off

egen country = group(idenpa)

tab idenpa
tab country 

gen SCone = 0
replace SCone = 1 if country==1 | country==4 | country==17 

recode S18 -7=. -6=0 -5=. -4=. -3=. -2=. -1=. 0=., gen(EdYears)   
recode P27ST -1=. -2=. -3=. -4=. -5=. -6=. -7=. -8=., gen(LRIdeology) 
gen Age = S13

recode P69ST_C -1=. -2=. -3=., gen(opposegay)
recode P25ST -2=. -1=. 2=0, gen(votemakesadifference)

proportion votemakesadifference if opposegay<3 
proportion votemakesadifference if opposegay>2

mean Age if opposegay<3 
mean Age if opposegay>2

mean EdYears if opposegay<3 
mean EdYears if opposegay>2

mean LRIdeology if opposegay<3 
mean LRIdeology if opposegay>2


gen SConeGay = SCone*opposegay 
gen EdGay = EdYears*opposegay
gen EdSCone = SCone*EdYears
gen SConeEdGay = SCone*EdYears*opposegay


proportion votemakesadifference if SCone==1
proportion votemakesadifference if SCone==0

proportion opposegay if SCone==1
proportion opposegay if SCone==0

proportion votemakesadifference if opposegay<3
proportion votemakesadifference if opposegay>2

mean EdYears if opposegay<3
mean EdYears if opposegay>2

mean Age if opposegay<3
mean Age if opposegay>2

mean LRIdeology if opposegay<3
mean LRIdeology if opposegay>2


#delimit ;
melogit votemakesadifference SCone opposegay EdYears
SConeGay EdGay EdSCone SConeEdGay
LRIdeology Age [pw=wt] ||idenpa:
;
#delimit cr


set more off 
			 
		sum LRIdeology
			gen LR_mean = r(mean)  
		sum Age 
			gen Age_mean = r(mean)
		sum EdYears
			gen Ed_mean = r(mean)
		
		keep if _n==1 
		keep LR_mean Age_mean  
		 
		matrix def b = e(b)
		matrix def V = e(V)
		mat list b
		mat list V
		
		set more off
		save FirstDifferencesIVs.dta, replace
		
		*program drop firstdiff2
	program define firstdiff2
	use FirstDifferencesIVs.dta, clear
	
	drawnorm b1-b11, means(b) cov(V)
	
	*Hi Education
	*Southern Cone
		#delimit ;
		gen pParticipation15d = b1*1 + b2*4 + b3*23 +
		b4*1*4 + b5*4*23 + b6*1*23 + b7*1*4*23 + 
		b8*LR_mean + b9*Age_mean + b10
		;
		#delimit cr

		#delimit ;
		gen pParticipation15nd = b1*1 + b2*1 + b3*23 +
		b4*1*1 + b5*1*23 + b6*1*23 + b7*1*1*23 + 
		b8*LR_mean + b9*Age_mean + b10 
		;
		#delimit cr
	
	*Non-Southern Cone
		#delimit ;
		gen pParticipationEd = b1*0 + b2*4 + b3*23 +
		b4*0*4 + b5*4*23 + b6*0*23 + b7*4*0*23 + 
		b8*LR_mean + b9*Age_mean + b10  
		;
		#delimit cr

		#delimit ;
		gen pParticipationEnd = b1*0 + b2*1 + b3*23 +
		b4*0*1 + b5*1*23 + b6*0*23 + b7*1*0*23 + 
		b8*LR_mean + b9*Age_mean + b10
		;
		#delimit cr
	
	
*Lo Education
	*Southern Cone
		#delimit ;
		gen OnepParticipation15d = b1*1 + b2*4 + b3*9 +
		b4*1*4 + b5*9*4 + b6*9*1 + b7*1*4*9 + 
		b8*LR_mean + b9*Age_mean + b10
		;
		#delimit cr

		#delimit ;
		gen OnepParticipation15nd = b1*1 + b2*1 + b3*9 +
		b4*1*1 + b5*9*1 + b6*9*1 + b7*9*1*1 + 
		b8*LR_mean + b9*Age_mean + b10  
		;
		#delimit cr
	
	*Non-Southern Cone 
		#delimit ;
		gen OnepParticipationEd = b1*0 + b2*4 + b3*9 +
		b4*0*4 + b5*4*9 + b6*0*9 + b7*4*0*9 + 
		b8*LR_mean + b9*Age_mean + b10  
		;
		#delimit cr

		#delimit ;
		gen OnepParticipationEnd = b1*0 + b2*1 + b3*9 +
		b4*0*1 + b5*9*1 + b6*0*9 + b7*1*0*9 + 
		b8*LR_mean + b9*Age_mean + b10
		;
		#delimit cr

		
		gen Participation15d = exp(pParticipation15d) / (1+exp(pParticipation15d))
		gen Participation15nd = exp(pParticipation15nd) / (1+exp(pParticipation15nd))
		gen ParticipationEd = exp(pParticipationEd)/ (1+exp(pParticipationEd))
		gen ParticipationEnd = exp(pParticipationEnd)/ (1+exp(pParticipationEnd))
		
		gen OneParticipation15d = exp(OnepParticipation15d) / (1+exp(OnepParticipation15d))
		gen OneParticipation15nd = exp(OnepParticipation15nd) / (1+exp(OnepParticipation15nd))
		gen OneParticipationEd = exp(OnepParticipationEd) / (1+exp(OnepParticipationEd))
		gen OneParticipationEnd = exp(OnepParticipationEnd) / (1+exp(OnepParticipationEnd))
		
		
		gen DiffEast = ParticipationEd - ParticipationEnd
		gen DiffWest = Participation15d - Participation15nd
		
		gen OneDiffEast = OneParticipationEd - OneParticipationEnd
		gen OneDiffWest = OneParticipation15d - OneParticipation15nd

		append using FirstDiffs2.dta
			save FirstDiffs2.dta, replace
			
			end
							
			clear
			save FirstDiffs2.dta, replace emptyok
	
			set more off

			simulate, reps(1500):  firstdiff2

			use FirstDiffs2.dta, clear

			
						set more off			
#delimit ; 
collapse (mean) 
Participation15d Participation15nd ParticipationEd ParticipationEnd DiffEast DiffWest
OneParticipation15d OneParticipation15nd OneParticipationEd OneParticipationEnd OneDiffEast OneDiffWest

 (sd)
 Participation15d_sd=Participation15d Participation15nd_sd=Participation15nd 
 ParticipationEd_sd=ParticipationEd ParticipationEnd_sd=ParticipationEnd
 DiffEast_sd=DiffEast  DiffWest_sd=DiffWest
 
 OneParticipation15d_sd=OneParticipation15d OneParticipation15nd_sd=OneParticipation15nd 
 OneParticipationEd_sd=OneParticipationEd OneParticipationEnd_sd=OneParticipationEnd
 OneDiffEast_sd=OneDiffEast  OneDiffWest_sd=OneDiffWest
 
 ;
#delimit cr 	


gen Participation15d_hi = Participation15d + 1.96*Participation15d_sd
gen Participation15d_lo = Participation15d - 1.96*Participation15d_sd

gen Participation15nd_hi = Participation15nd + 1.96*Participation15nd_sd
gen Participation15nd_lo = Participation15nd - 1.96*Participation15nd_sd

gen ParticipationEd_hi = ParticipationEd + 1.96*ParticipationEd_sd
gen ParticipationEd_lo = ParticipationEd - 1.96*ParticipationEd_sd

gen ParticipationEnd_hi = ParticipationEnd + 1.96*ParticipationEnd_sd
gen ParticipationEnd_lo = ParticipationEnd - 1.96*ParticipationEnd_sd 

gen DiffEast_hi = DiffEast + 1.96*DiffEast_sd
gen DiffEast_lo = DiffEast - 1.96*DiffEast_sd

gen DiffWest_hi = DiffWest + 1.96*DiffWest_sd
gen DiffWest_lo = DiffWest - 1.96*DiffWest_sd





gen OneParticipation15d_hi = OneParticipation15d + 1.96*OneParticipation15d_sd
gen OneParticipation15d_lo = OneParticipation15d - 1.96*OneParticipation15d_sd

gen OneParticipation15nd_hi = OneParticipation15nd + 1.96*OneParticipation15nd_sd
gen OneParticipation15nd_lo = OneParticipation15nd - 1.96*OneParticipation15nd_sd

gen OneParticipationEd_hi = OneParticipationEd + 1.96*OneParticipationEd_sd
gen OneParticipationEd_lo = OneParticipationEd - 1.96*OneParticipationEd_sd

gen OneParticipationEnd_hi = OneParticipationEnd + 1.96*OneParticipationEnd_sd
gen OneParticipationEnd_lo = OneParticipationEnd - 1.96*OneParticipationEnd_sd 

gen OneDiffEast_hi = OneDiffEast + 1.96*OneDiffEast_sd
gen OneDiffEast_lo = OneDiffEast - 1.96*OneDiffEast_sd

gen OneDiffWest_hi = OneDiffWest + 1.96*OneDiffWest_sd
gen OneDiffWest_lo = OneDiffWest - 1.96*OneDiffWest_sd

browse

gen axis_LFS1_B = 1
gen axis_LFS2_B = 2
gen axis_LFS3_B = 3
gen axis_LFS4_B = 4

lab def afmtlf2 1 "Homophobic" 2 "Tolerant" 3 "Homophobic" 4 "Tolerant" 
label val axis_LFS1_B afmtlf2 

#delimit ;
twoway (bar Participation15d axis_LFS1_B, 
			color(black) barwidth(.5))
		(rcap Participation15d_lo Participation15d_hi axis_LFS1_B,
			lcolor(gs10))
		(bar Participation15nd axis_LFS2_B, 
			color(black) barwidth(.5))
		(rcap Participation15nd_lo Participation15nd_hi axis_LFS2_B,
			lcolor(gs10))
		(bar ParticipationEd axis_LFS3_B , 
			color(gs10) barwidth(.5))
		(rcap ParticipationEd_lo ParticipationEd_hi axis_LFS3_B,
			lcolor(black))
		(bar ParticipationEnd axis_LFS4_B, 
			color(gs10) barwidth(.5))
		(rcap ParticipationEnd_lo ParticipationEnd_hi axis_LFS4_B,
			lcolor(black)),
legend(off)
ylabel(.2(.2)1)
ytitle("Pr(Vote Makes a Difference)", size(small))
title("High Education Level", size(medium))
xlabel(#3,valuelabel angle(horizontal))
name(GPH1, replace)
scheme(s1mono);
#delimit cr	


	    #delimit ;
		twoway (bar DiffWest axis_LFS1_B, color(black)) (rcap DiffWest_hi DiffWest_lo axis_LFS1_B, color(gs10)) 
		(bar DiffEast axis_LFS2_B, color(gs10)) (rcap DiffEast_hi DiffEast_lo axis_LFS2_B, color(black)), 
		scheme(s1mono) ylabel(.2(.1) -.3) ytitle("Difference in Pr(Vote Makes a Difference)", size(small))
		yline(0)
		xlabel( 1 "Southern Cone" 2 "Not in the Southern Cone", noticks) 
		name(GPH2, replace)  
		 legend(off)
		;
		#delimit cr
		


		#delimit ;
		twoway (bar OneParticipation15d axis_LFS1_B, 
			color(black) barwidth(.5))
		(rcap OneParticipation15d_lo OneParticipation15d_hi axis_LFS1_B,
			lcolor(gs10))
		(bar OneParticipation15nd axis_LFS2_B, 
			color(black) barwidth(.5))
		(rcap OneParticipation15nd_lo OneParticipation15nd_hi axis_LFS2_B,
			lcolor(gs10))
		(bar OneParticipationEd axis_LFS3_B , 
			color(gs10) barwidth(.5))
		(rcap OneParticipationEd_lo OneParticipationEd_hi axis_LFS3_B,
			lcolor(black))
		(bar OneParticipationEnd axis_LFS4_B, 
			color(gs10) barwidth(.5))
		(rcap OneParticipationEnd_lo OneParticipationEnd_hi axis_LFS4_B,
			lcolor(black)),
legend(off)
ylabel(.2(.2) 1)
ytitle("Pr(Vote Makes a Difference)", size(small))
title("Low Education Level", size(medium))
xlabel(#3,valuelabel angle(horizontal))
name(GPH3, replace)
scheme(s1mono);
#delimit cr	


	    #delimit ;
		twoway (bar OneDiffWest axis_LFS1_B, color(black)) (rcap OneDiffWest_hi OneDiffWest_lo axis_LFS1_B, color(gs10)) 
		(bar OneDiffEast axis_LFS2_B, color(gs10)) (rcap OneDiffEast_hi OneDiffEast_lo axis_LFS2_B, color(black)), 
		scheme(s1mono) ylabel(.2(.1) -.3) ytitle("Difference in Pr(Vote Makes a Difference)", size(small))
		yline(0)
		xlabel( 1 "Southern Cone" 2 "Not in the Southern Cone", noticks) 
		name(GPH4, replace)  
		 legend(off)
		;
		#delimit cr
			

#delimit ;	
	graph combine GPH1 GPH3 GPH2 GPH4, rows(2) title("A1Figure2: Probability to believe one's vote makes a difference by agreement" 
	"with same-sex marriage, education, and whether one lives in the Southern Cone" "with 95 percent confidence intervals.", size(medsmall))
note("Dependent variable: My vote makes a difference(1), Not my vote makes a difference(0)." "Data source: Latinobarometer 2015", size(medsmall)) scheme(s1mono)
;
#delimit cr
 


